package cn.icanci.service.combine.impl;

import cn.icanci.entity.bo.HeadLine;
import cn.icanci.entity.bo.ShopCategory;
import cn.icanci.entity.dto.MainPageInfoDTO;
import cn.icanci.entity.dto.Result;
import cn.icanci.service.combine.HeadLineShopCategoryCombineService;
import cn.icanci.service.solo.HeadLineService;
import cn.icanci.service.solo.ShopCategoryService;

import java.util.List;

import org.simpleframework.core.annotation.Service;
import org.simpleframework.inject.annotation.Autowired;

/**
 * 首页信息实现类
 *
 * @author icanci
 * @date Created in 2021/02/03 23:26
 * @version 1.0
 */
@Service
public class HeadLineShopCategoryCombineServiceImpl implements HeadLineShopCategoryCombineService {
    @Autowired
    private HeadLineService     headLineService;
    @Autowired
    private ShopCategoryService shopCategoryService;

    @Override
    public Result<MainPageInfoDTO> getMainPageInfo() {
        // 1.获取头条列表
        HeadLine headLineCondition = new HeadLine();
        headLineCondition.setEnableStatus(1);
        Result<List<HeadLine>> headLineListResult = headLineService.queryHeadLine(headLineCondition, 1, 4);
        // 2.获取商铺列表
        ShopCategory shopCategoryCondition = new ShopCategory();
        Result<List<ShopCategory>> shopCategoryListResult = shopCategoryService.queryShopCategory(shopCategoryCondition, 1, 100);
        // 3.合并数据返回
        Result<MainPageInfoDTO> mainPageInfoDTOResult = mergeMainPageInfoResult(headLineListResult, shopCategoryListResult);
        return mainPageInfoDTOResult;
    }

    /**
     * 返回组装收据
     * @param headLineListResult headLineListResult
     * @param shopCategoryListResult shopCategoryListResult
     * @return 组装数据
     */
    private Result<MainPageInfoDTO> mergeMainPageInfoResult(Result<List<HeadLine>> headLineListResult, Result<List<ShopCategory>> shopCategoryListResult) {
        MainPageInfoDTO mainPageInfoDTO = new MainPageInfoDTO();
        mainPageInfoDTO.setHeadLineList(headLineListResult.getData());
        mainPageInfoDTO.setShopCategoryList(shopCategoryListResult.getData());
        Result<MainPageInfoDTO> mainPageInfoDTOResult = new Result<>();
        mainPageInfoDTOResult.setCode(200);
        mainPageInfoDTOResult.setMsg("success");
        mainPageInfoDTOResult.setData(mainPageInfoDTO);
        return mainPageInfoDTOResult;
    }
}
